﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.POConfig.Business
{
    public class ApiConfig : POBaseConfig<ApiPO>
    {
        public override void InitializeData(EntityTypeBuilder<ApiPO> builder)
        {
        }

        public override void MapColumn(EntityTypeBuilder<ApiPO> builder, ref int index)
        {
            builder.HasComment("接口表");
            builder.Property(entity => entity.Code).ConfigColumn("CODE", "编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.Api).ConfigColumn("API", "地址", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TimeOut).ConfigColumn("TIME_OUT", "超时时间").HasColumnOrder(index++);
            builder.Property(entity => entity.IsEnabled).ConfigColumn("IS_ENABLED", "启用").HasColumnOrder(index++);
            builder.Property(entity => entity.UserName).ConfigColumn("USER_NAME", "用户名称", 100).HasColumnOrder(index++);
            builder.Property(entity => entity.Password).ConfigColumn("PASSWORD", "密码", 200).HasColumnOrder(index++);
            builder.Property(entity => entity.WarehouseCode).ConfigColumn("WAREHOUSE_CODE", "仓库编码", 50, true).HasColumnOrder(index++);
        }

        public override void MapIndex(EntityTypeBuilder<ApiPO> builder)
        {
            builder.HasIndex(entity => new { entity.Code, entity.WarehouseCode }).HasDatabaseName($"UN_{TableName}_1").IsUnique();
        }
    }
}
